package com.liuning.graduationdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import com.liuning.graduationdemo.service.IDictService;
import com.liuning.graduationdemo.entity.Dict;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pumpkin
 * @since 2022-04-12
 */
@RestController
@RequestMapping("/dict")
public class DictController {

    @Resource
    private IDictService dictService;

    @PostMapping
    public Boolean save(@RequestBody Dict dict) {
        return dictService.saveOrUpdate(dict);
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return dictService.removeById(id);
    }

    @GetMapping
    public List<Dict> findAll() {
        return dictService.list();
    }

    @GetMapping("/{id}")
    public Dict findOne(@PathVariable Integer id) {
        return dictService.getById(id);
    }

    @GetMapping("/page")
    public Page<Dict> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return dictService.page(new Page<>(pageNum, pageSize),queryWrapper);
    }

    //批量删除
    @PostMapping("/del/batch")
    public boolean batchDelete(@RequestBody List<Integer> ids) {
        return dictService.removeBatchByIds(ids);
    }


}

